home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / we32m30d.zip / DLLCALL.ZI_ / DCTST16I.C < prev    next >
C/C++ Source or Header  |  1993-07-30  |  2KB  |  85 lines

  1. #include "windows.h"
  2.  
  3. // This file contains sample C code for writing a DLL that can be called
  4. // from a WIL Script file to build commands of the users own choosing.
  5. // This is the Windows 3.1 16 bit version
  6.  
  7.  
  8. char BugBypass[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";  //Superstitious inclusion
  9.  
  10. HINSTANCE hThisInstance;   //A place to save this DLL's instance handle
  11.  
  12.  
  13. /********************************************************************/
  14. int WINAPI WEP(int nP)
  15. {
  16. nP;        // Never Referenced
  17. return 1;
  18. }
  19. /********************************************************************/
  20.  
  21. BOOL WINAPI LibInit (
  22.    HANDLE   hInstance,
  23.    WORD     wDataSeg,
  24.    WORD     wHeapSize,
  25.    LPSTR    lpCmdLine)
  26.      {
  27.  
  28.      hInstance;
  29.      wDataSeg;
  30.      wHeapSize;
  31.      lpCmdLine;
  32.  
  33.      if (wHeapSize==0)
  34.         {
  35.         return FALSE;
  36.         }
  37.      if (!LocalInit(wDataSeg, NULL, (WORD)(NPSTR) wHeapSize))  return FALSE;
  38.  
  39.      hThisInstance=hInstance;     // Save Instance Handle
  40.      return TRUE;
  41.       }
  42.  
  43. /************************************************************************/
  44.  
  45. // MyEntryPoint - the same as the second parameter of the DllCall statement
  46. GLOBALHANDLE WINAPI MyEntryPoint(HWND hWnd,LPSTR szParams)
  47. {
  48. char szAns[128];
  49. int i;
  50. GLOBALHANDLE ghTemp;
  51. LPSTR lpTemp;
  52.  
  53.  
  54. // Display message box showing passed parameters  (szParams) wich is the
  55. // third argument of the DllCall statement
  56.  
  57. MessageBox(hWnd,szParams,"DLL CALL TEST - Passed info is",MB_OK);
  58.  
  59.  
  60.  
  61. // And now to show how to get a string back to a WIL variable.  Only strings
  62. // may be returned.  If you need to return a number....convert it to a
  63. // string first.
  64.  
  65.  
  66. // First of all manufacture an answer.  We just load it from the RC file
  67. i=LoadString(hThisInstance,1,szAns,sizeof(szAns));
  68.  
  69. // Then GlobalAlloc a memory buffer ONE BIGGER than the string
  70. ghTemp=GlobalAlloc(GMEM_MOVEABLE,(DWORD)i+1);
  71.  
  72. if (ghTemp)                      // And if it was properly allocated
  73.     {
  74.     lpTemp=GlobalLock(ghTemp);   // Lock it down and get a memory address
  75.     if (lpTemp)                  // And if that worked,
  76.        {
  77.        lstrcpy(lpTemp,szAns);    // Copy our answer to GlobalMemory
  78.        GlobalUnlock(ghTemp);     // Unlock the buffer
  79.        }
  80.     }
  81. return ghTemp;   //Return unlocked buffer.  WIL will free GlobalFree buffer
  82. }
  83.  
  84.  
  85.